// import nativeApp from '@/utils/nativeApp'
import { deviceType } from '@/utils/deviceType'
export default function mid(context) {
  context.userAgent = process.server ? context.req.headers['user-agent'] : navigator.userAgent
  // 给全局上下文添加一个属性来保存我们返回的匹配信息
  context.deviceType = deviceType(context.userAgent)
  // 这里注入到store,是因为我部分页面需要判断机型请求不同的数据,
  // 你们没有用到的话可以移除
  context.store.dispatch('setDeviceType', context.deviceType)
  // 若是判断UA非移动端的,就在这里做处理了..
  // context.redirect(status,url) 这个可以重定向到外部网站
  // 若是内部访问可以直接用router对象push
  if (context.deviceType.type === 'ios' || context.deviceType.type === 'android') {
    if (context.route.name === 'index') {
      context.redirect(301, 'https://m.rongcat.com/?page=1&tab=')
    } else if (context.route.name === 'content') {
      context.redirect(301, 'https://m.rongcat.com/moment?page=1')
    } else if (context.route.name === 'content-details') {
      context.redirect(301, `https://m.rongcat.com/moment/${context.route.params.details}`)
    } else if (context.route.name === 'product') {
      context.redirect(301, `https://m.rongcat.com/mall?page=1`)
    } else if (context.route.name === 'product-details') {
      context.redirect(301, `https://m.rongcat.com/product/${context.route.params.details}`)
    } else if (context.route.name === 'diary-details') {
      context.redirect(301, `https://m.rongcat.com/diary/${context.route.params.details}`)
    } else if (context.route.name === 'diary') {
      context.redirect(301, 'https://m.rongcat.com/diary')
    } else if (context.route.name === 'hospital') {
      context.redirect(301, 'https://m.rongcat.com/hospital?page=1')
    } else if (context.route.name === 'hospital-details') {
      context.redirect(301, `https://m.rongcat.com/hospital/${context.route.params.details}`)
    } else if (context.route.name === 'doctor') {
      context.redirect(301, 'https://m.rongcat.com/doctor?page=1')
    } else if (context.route.name === 'doctor-details') {
      context.redirect(301, `https://m.rongcat.com/doctor/${context.route.params.details}`)
    } else if (context.route.name === 'encyclopedias') {
      context.redirect(301, 'https://m.rongcat.com/wiki')
    } else if (context.route.name === 'encyclopedias-details') {
      context.redirect(301, `https://m.rongcat.com/wiki/${context.route.params.details}`)
    } else if (context.route.name === 'article') {
      context.redirect(301, 'https://m.rongcat.com/article?page=1')
    } else if (context.route.name === 'article-details') {
      context.redirect(301, `https://m.rongcat.com/article/${context.route.params.details}`)
    } else if (context.route.name === 'question') {
      context.redirect(301, 'https://m.rongcat.com/question?page=1')
    } else if (context.route.name === 'question-details') {
      context.redirect(301, `https://m.rongcat.com/question/${context.route.params.details}`)
    } else if (context.route.name === 'search-details') {
      context.redirect(301, `https://m.rongcat.com/search/${encodeURIComponent(context.route.params.details)}`)
    }
  }
}
